package com.example.inventory.model.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;

import java.time.LocalDateTime;

/**
 * 库存操作日志实体类
 * 对应数据库表 t_inventory_log
 * 
 * @author mall-team
 */
@Entity
@Table(name = "t_inventory_log")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class InventoryLog {

    /**
     * 日志ID（主键）
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * SKU ID
     */
    @Column(name = "sku_id", nullable = false)
    private Long skuId;

    /**
     * 订单编号
     */
    @Column(name = "order_no", nullable = false, length = 64)
    private String orderNo;

    /**
     * 操作类型
     * RESERVE: 预留库存
     * RELEASE: 释放库存
     * DEDUCT: 扣减库存
     */
    @Column(name = "operation_type", nullable = false, length = 32)
    private String operationType;

    /**
     * 变更数量（正数表示增加，负数表示减少）
     */
    @Column(name = "quantity", nullable = false)
    private Integer quantity;

    /**
     * 操作前库存数量
     */
    @Column(name = "before_quantity", nullable = false)
    private Integer beforeQuantity;

    /**
     * 操作后库存数量
     */
    @Column(name = "after_quantity", nullable = false)
    private Integer afterQuantity;

    /**
     * 备注
     */
    @Column(name = "remark", length = 500)
    private String remark;

    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(name = "created_at", nullable = false, updatable = false)
    private LocalDateTime createdAt;
}

